package com.zbkj.admin.controller.platform.assistant;


import com.zbkj.admin.controller.platform.assistant.service.AssistantQuickReplyService;
import com.zbkj.common.model.assistant.AssistantQuickReply;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.result.CommonResult;
import com.zbkj.service.assistant.model.request.AssistantQuickReplyRequest;
import com.zbkj.service.assistant.model.request.AssistantQuickReplySearchRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;


/**
 * 快捷回复表 前端控制器
 */
@Slf4j
@RestController
@RequestMapping("api/admin/platform/assistant/quick-reply")
@Api(tags = "客服-快捷回复") //配合swagger使用

public class AssistantQuickReplyController {

    @Autowired
    private AssistantQuickReplyService assistantQuickReplyService;

    /**
     * 分页显示快捷回复表
     * @param request 搜索条件
     * @author keNan
     * @since 2025-06-11
     */
    @ApiOperation(value = "分页列表") //配合swagger使用
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<AssistantQuickReply>>  getList(@Validated AssistantQuickReplySearchRequest request) {
        CommonPage<AssistantQuickReply> assistantQuickReplyCommonPage = CommonPage.restPage(assistantQuickReplyService.getPage(request));
        return CommonResult.success(assistantQuickReplyCommonPage);
    }

    /**
     * 新增快捷回复表
     * @param assistantQuickReplyRequest 新增参数
     * @author keNan
     * @since 2025-06-11
     */
    @ApiOperation(value = "新增")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public CommonResult<String> save(@RequestBody @Validated AssistantQuickReplyRequest assistantQuickReplyRequest) {
        AssistantQuickReply assistantQuickReply = new AssistantQuickReply();
        BeanUtils.copyProperties(assistantQuickReplyRequest, assistantQuickReply);

        if(assistantQuickReplyService.save(assistantQuickReply)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * 删除快捷回复表
     * @param id Integer
     * @author keNan
     * @since 2025-06-11
     */
    @ApiOperation(value = "删除")
    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    public CommonResult<String> delete(@RequestParam(value = "id") Integer id) {
        if(assistantQuickReplyService.removeById(id)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * 修改快捷回复表
     * @param assistantQuickReplyRequest 修改参数
     * @author keNan
     * @since 2025-06-11
     */
    @ApiOperation(value = "修改")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public CommonResult<String> update(@RequestBody @Validated AssistantQuickReplyRequest assistantQuickReplyRequest) {
        AssistantQuickReply assistantQuickReply = new AssistantQuickReply();
        BeanUtils.copyProperties(assistantQuickReplyRequest, assistantQuickReply);

        if(assistantQuickReplyService.updateById(assistantQuickReply)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * 查询快捷回复表信息
     * @param id Integer
     * @author keNan
     * @since 2025-06-11
     */
    @ApiOperation(value = "详情")
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    public CommonResult<AssistantQuickReply> info(@RequestParam(value = "id") Integer id) {
        AssistantQuickReply assistantQuickReply = assistantQuickReplyService.getById(id);
        return CommonResult.success(assistantQuickReply);
    }
}



